@contentful/field-editor-markdown 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/MarkdownActions.js +235 -0
- package/dist/cjs/MarkdownEditor.js +180 -0
- package/dist/cjs/__fixtures__/FakeSdk.js +183 -0
- package/dist/cjs/__fixtures__/asset/index.js +37 -0
- package/dist/cjs/__fixtures__/content-type/index.js +16 -0
- package/dist/cjs/__fixtures__/entry/index.js +33 -0
- package/dist/cjs/__fixtures__/fixtures.js +71 -0
- package/dist/cjs/__fixtures__/locale/index.js +40 -0
- package/dist/cjs/__fixtures__/space/index.js +16 -0
- package/dist/cjs/codemirrorImports.js +9 -0
- package/dist/cjs/components/HeadingSelector.js +66 -0
- package/dist/cjs/components/InsertLinkSelector.js +86 -0
- package/dist/cjs/components/MarkdownBottomBar.js +111 -0
- package/dist/cjs/components/MarkdownConstraints.js +79 -0
- package/dist/cjs/components/MarkdownPreview.js +249 -0
- package/dist/cjs/components/MarkdownTabs.js +128 -0
- package/dist/cjs/components/MarkdownTextarea/CodeMirrorWrapper.js +383 -0
- package/dist/cjs/components/MarkdownTextarea/MarkdownCommands.js +233 -0
- package/dist/cjs/components/MarkdownTextarea/MarkdownTextarea.js +190 -0
- package/dist/cjs/components/MarkdownTextarea/createMarkdownEditor.js +101 -0
- package/dist/cjs/components/MarkdownToolbar.js +367 -0
- package/dist/cjs/components/icons.js +193 -0
- package/dist/cjs/dialogs/CheatsheetModalDialog.js +239 -0
- package/dist/cjs/dialogs/ConfirmInsertAssetModalDialog.js +94 -0
- package/dist/cjs/dialogs/EmdebExternalContentDialog.js +202 -0
- package/dist/cjs/dialogs/InsertLinkModalDialog.js +149 -0
- package/dist/cjs/dialogs/InsertTableModalDialog.js +140 -0
- package/dist/cjs/dialogs/SpecialCharacterModalDialog.js +146 -0
- package/dist/cjs/dialogs/ZenModeModalDialog.js +257 -0
- package/dist/cjs/dialogs/openMarkdownDialog.js +121 -0
- package/dist/cjs/dialogs/renderMarkdownDialog.js +108 -0
- package/dist/cjs/index.js +29 -0
- package/dist/cjs/types.js +20 -0
- package/dist/cjs/utils/insertAssetLinks.js +122 -0
- package/dist/cjs/utils/insertAssetLinks.spec.js +22 -0
- package/dist/cjs/utils/isValidUrl.js +22 -0
- package/dist/cjs/utils/linkOrganizer.js +187 -0
- package/dist/cjs/utils/linkOrganizer.spec.js +96 -0
- package/dist/cjs/utils/replaceMailtoAmp.js +15 -0
- package/dist/cjs/utils/replaceMailtoAmp.spec.js +22 -0
- package/dist/cjs/utils/specialCharacters.js +228 -0
- package/dist/cjs/utils/userAgent.js +28 -0
- package/dist/esm/MarkdownActions.js +186 -0
- package/dist/esm/MarkdownEditor.js +118 -0
- package/dist/esm/__fixtures__/FakeSdk.js +173 -0
- package/dist/esm/__fixtures__/asset/index.js +6 -0
- package/dist/esm/__fixtures__/content-type/index.js +2 -0
- package/dist/esm/__fixtures__/entry/index.js +5 -0
- package/dist/esm/__fixtures__/fixtures.js +6 -0
- package/dist/esm/__fixtures__/locale/index.js +15 -0
- package/dist/esm/__fixtures__/space/index.js +2 -0
- package/dist/esm/codemirrorImports.js +5 -0
- package/dist/esm/components/HeadingSelector.js +17 -0
- package/dist/esm/components/InsertLinkSelector.js +37 -0
- package/dist/esm/components/MarkdownBottomBar.js +46 -0
- package/dist/esm/components/MarkdownConstraints.js +25 -0
- package/dist/esm/components/MarkdownPreview.js +195 -0
- package/dist/esm/components/MarkdownTabs.js +74 -0
- package/dist/esm/components/MarkdownTextarea/CodeMirrorWrapper.js +329 -0
- package/dist/esm/components/MarkdownTextarea/MarkdownCommands.js +218 -0
- package/dist/esm/components/MarkdownTextarea/MarkdownTextarea.js +136 -0
- package/dist/esm/components/MarkdownTextarea/createMarkdownEditor.js +52 -0
- package/dist/esm/components/MarkdownToolbar.js +302 -0
- package/dist/esm/components/icons.js +112 -0
- package/dist/esm/dialogs/CheatsheetModalDialog.js +177 -0
- package/dist/esm/dialogs/ConfirmInsertAssetModalDialog.js +37 -0
- package/dist/esm/dialogs/EmdebExternalContentDialog.js +140 -0
- package/dist/esm/dialogs/InsertLinkModalDialog.js +92 -0
- package/dist/esm/dialogs/InsertTableModalDialog.js +78 -0
- package/dist/esm/dialogs/SpecialCharacterModalDialog.js +84 -0
- package/dist/esm/dialogs/ZenModeModalDialog.js +195 -0
- package/dist/esm/dialogs/openMarkdownDialog.js +72 -0
- package/dist/esm/dialogs/renderMarkdownDialog.js +59 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/types.js +10 -0
- package/dist/esm/utils/insertAssetLinks.js +99 -0
- package/dist/esm/utils/insertAssetLinks.spec.js +18 -0
- package/dist/esm/utils/isValidUrl.js +4 -0
- package/dist/esm/utils/linkOrganizer.js +152 -0
- package/dist/esm/utils/linkOrganizer.spec.js +53 -0
- package/dist/esm/utils/replaceMailtoAmp.js +5 -0
- package/dist/esm/utils/replaceMailtoAmp.spec.js +18 -0
- package/dist/esm/utils/specialCharacters.js +218 -0
- package/dist/esm/utils/userAgent.js +13 -0
- package/dist/{MarkdownActions.d.ts → types/MarkdownActions.d.ts} +38 -38
- package/dist/{MarkdownEditor.d.ts → types/MarkdownEditor.d.ts} +22 -22
- package/dist/types/__fixtures__/FakeSdk.d.ts +8 -0
- package/dist/types/__fixtures__/asset/index.d.ts +6 -0
- package/dist/types/__fixtures__/content-type/index.d.ts +2 -0
- package/dist/types/__fixtures__/entry/index.d.ts +5 -0
- package/dist/types/__fixtures__/fixtures.d.ts +6 -0
- package/dist/types/__fixtures__/locale/index.d.ts +42 -0
- package/dist/types/__fixtures__/space/index.d.ts +2 -0
- package/dist/{codemirrorImports.d.ts → types/codemirrorImports.d.ts} +5 -5
- package/dist/{components → types/components}/HeadingSelector.d.ts +7 -7
- package/dist/{components → types/components}/InsertLinkSelector.d.ts +9 -9
- package/dist/{components → types/components}/MarkdownBottomBar.d.ts +11 -11
- package/dist/{components → types/components}/MarkdownConstraints.d.ts +6 -6
- package/dist/{components → types/components}/MarkdownPreview.d.ts +14 -14
- package/dist/{components → types/components}/MarkdownTabs.d.ts +8 -8
- package/dist/{components → types/components}/MarkdownTextarea/CodeMirrorWrapper.d.ts +58 -58
- package/dist/{components → types/components}/MarkdownTextarea/MarkdownCommands.d.ts +33 -33
- package/dist/{components → types/components}/MarkdownTextarea/MarkdownTextarea.d.ts +17 -17
- package/dist/{components → types/components}/MarkdownTextarea/createMarkdownEditor.d.ts +55 -55
- package/dist/{components → types/components}/MarkdownToolbar.d.ts +12 -12
- package/dist/types/components/icons.d.ts +18 -0
- package/dist/{dialogs → types/dialogs}/CheatsheetModalDialog.d.ts +4 -4
- package/dist/{dialogs → types/dialogs}/ConfirmInsertAssetModalDialog.d.ts +23 -23
- package/dist/{dialogs → types/dialogs}/EmdebExternalContentDialog.d.ts +9 -9
- package/dist/{dialogs → types/dialogs}/InsertLinkModalDialog.d.ts +17 -17
- package/dist/{dialogs → types/dialogs}/InsertTableModalDialog.d.ts +13 -13
- package/dist/{dialogs → types/dialogs}/SpecialCharacterModalDialog.d.ts +9 -9
- package/dist/{dialogs → types/dialogs}/ZenModeModalDialog.d.ts +24 -24
- package/dist/{dialogs → types/dialogs}/openMarkdownDialog.d.ts +5 -5
- package/dist/{dialogs → types/dialogs}/renderMarkdownDialog.d.ts +8 -8
- package/dist/{index.d.ts → types/index.d.ts} +5 -5
- package/dist/{types.d.ts → types/types.d.ts} +75 -75
- package/dist/{utils → types/utils}/insertAssetLinks.d.ts +29 -29
- package/dist/types/utils/insertAssetLinks.spec.d.ts +1 -0
- package/dist/{utils → types/utils}/isValidUrl.d.ts +2 -2
- package/dist/{utils → types/utils}/linkOrganizer.d.ts +6 -6
- package/dist/types/utils/linkOrganizer.spec.d.ts +1 -0
- package/dist/{utils → types/utils}/replaceMailtoAmp.d.ts +1 -1
- package/dist/types/utils/replaceMailtoAmp.spec.d.ts +1 -0
- package/dist/{utils → types/utils}/specialCharacters.d.ts +4 -4
- package/dist/{utils → types/utils}/userAgent.d.ts +1 -1
- package/package.json +25 -11
- package/CHANGELOG.md +0 -308
- package/dist/components/icons.d.ts +0 -18
- package/dist/field-editor-markdown.cjs.development.js +0 -3605
- package/dist/field-editor-markdown.cjs.development.js.map +0 -1
- package/dist/field-editor-markdown.cjs.production.min.js +0 -216
- package/dist/field-editor-markdown.cjs.production.min.js.map +0 -1
- package/dist/field-editor-markdown.esm.js +0 -3595
- package/dist/field-editor-markdown.esm.js.map +0 -1
- package/dist/index.js +0 -8
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "createMarkdownActions", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createMarkdownActions;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _ConfirmInsertAssetModalDialog = require("./dialogs/ConfirmInsertAssetModalDialog");
|
|
12
|
+
const _EmdebExternalContentDialog = require("./dialogs/EmdebExternalContentDialog");
|
|
13
|
+
const _InsertLinkModalDialog = require("./dialogs/InsertLinkModalDialog");
|
|
14
|
+
const _InsertTableModalDialog = require("./dialogs/InsertTableModalDialog");
|
|
15
|
+
const _SpecialCharacterModalDialog = require("./dialogs/SpecialCharacterModalDialog");
|
|
16
|
+
const _ZenModeModalDialog = require("./dialogs/ZenModeModalDialog");
|
|
17
|
+
const _insertAssetLinks = require("./utils/insertAssetLinks");
|
|
18
|
+
const _linkOrganizer = _interop_require_wildcard(require("./utils/linkOrganizer"));
|
|
19
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
20
|
+
if (typeof WeakMap !== "function") return null;
|
|
21
|
+
var cacheBabelInterop = new WeakMap();
|
|
22
|
+
var cacheNodeInterop = new WeakMap();
|
|
23
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
24
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
25
|
+
})(nodeInterop);
|
|
26
|
+
}
|
|
27
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
28
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
32
|
+
return {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
37
|
+
if (cache && cache.has(obj)) {
|
|
38
|
+
return cache.get(obj);
|
|
39
|
+
}
|
|
40
|
+
var newObj = {};
|
|
41
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
42
|
+
for(var key in obj){
|
|
43
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
44
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
45
|
+
if (desc && (desc.get || desc.set)) {
|
|
46
|
+
Object.defineProperty(newObj, key, desc);
|
|
47
|
+
} else {
|
|
48
|
+
newObj[key] = obj[key];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
newObj.default = obj;
|
|
53
|
+
if (cache) {
|
|
54
|
+
cache.set(obj, newObj);
|
|
55
|
+
}
|
|
56
|
+
return newObj;
|
|
57
|
+
}
|
|
58
|
+
function createMarkdownActions(props) {
|
|
59
|
+
const { sdk , editor , locale } = props;
|
|
60
|
+
const insertAssetsWithConfirmation = async (assets)=>{
|
|
61
|
+
if (assets) {
|
|
62
|
+
const { links , fallbacks } = await (0, _insertAssetLinks.insertAssetLinks)(assets, {
|
|
63
|
+
localeCode: locale,
|
|
64
|
+
defaultLocaleCode: sdk.locales.default,
|
|
65
|
+
fallbackCode: sdk.locales.fallbacks[locale]
|
|
66
|
+
});
|
|
67
|
+
if (links && links.length > 0) {
|
|
68
|
+
if (fallbacks) {
|
|
69
|
+
const insertAnyway = await (0, _ConfirmInsertAssetModalDialog.openConfirmInsertAsset)(sdk.dialogs, {
|
|
70
|
+
locale: locale,
|
|
71
|
+
assets: fallbacks
|
|
72
|
+
});
|
|
73
|
+
if (!insertAnyway) {
|
|
74
|
+
throw Error('User decided to not use fallbacks');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return links.map((link)=>link.asMarkdown).join('\n\n');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return '';
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
headings: {
|
|
84
|
+
h1: ()=>{
|
|
85
|
+
editor?.actions.h1();
|
|
86
|
+
},
|
|
87
|
+
h2: ()=>{
|
|
88
|
+
editor?.actions.h2();
|
|
89
|
+
},
|
|
90
|
+
h3: ()=>{
|
|
91
|
+
editor?.actions.h3();
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
simple: {
|
|
95
|
+
italic: ()=>{
|
|
96
|
+
editor?.actions.italic();
|
|
97
|
+
},
|
|
98
|
+
bold: ()=>{
|
|
99
|
+
editor?.actions.bold();
|
|
100
|
+
},
|
|
101
|
+
quote: ()=>{
|
|
102
|
+
editor?.actions.quote();
|
|
103
|
+
},
|
|
104
|
+
ol: ()=>{
|
|
105
|
+
editor?.actions.ol();
|
|
106
|
+
},
|
|
107
|
+
ul: ()=>{
|
|
108
|
+
editor?.actions.ul();
|
|
109
|
+
},
|
|
110
|
+
strike: ()=>{
|
|
111
|
+
editor?.actions.strike();
|
|
112
|
+
},
|
|
113
|
+
code: ()=>{
|
|
114
|
+
editor?.actions.code();
|
|
115
|
+
},
|
|
116
|
+
hr: ()=>{
|
|
117
|
+
editor?.actions.hr();
|
|
118
|
+
},
|
|
119
|
+
indent: ()=>{
|
|
120
|
+
editor?.actions.indent();
|
|
121
|
+
},
|
|
122
|
+
dedent: ()=>{
|
|
123
|
+
editor?.actions.dedent();
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
history: {
|
|
127
|
+
undo: ()=>{
|
|
128
|
+
editor?.actions.undo();
|
|
129
|
+
},
|
|
130
|
+
redo: ()=>{
|
|
131
|
+
editor?.actions.redo();
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
insertLink: async ()=>{
|
|
135
|
+
if (!editor) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
editor.usePrimarySelection();
|
|
139
|
+
const selectedText = editor.getSelectedText();
|
|
140
|
+
const result = await (0, _InsertLinkModalDialog.openInsertLinkDialog)(sdk.dialogs, {
|
|
141
|
+
selectedText
|
|
142
|
+
});
|
|
143
|
+
if (result) {
|
|
144
|
+
editor.actions.link(result.url, selectedText || result.text, result.title);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
insertSpecialCharacter: async ()=>{
|
|
148
|
+
if (!editor) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const result = await (0, _SpecialCharacterModalDialog.openInsertSpecialCharacter)(sdk.dialogs);
|
|
152
|
+
if (result) {
|
|
153
|
+
editor.insert(result);
|
|
154
|
+
}
|
|
155
|
+
},
|
|
156
|
+
insertTable: async ()=>{
|
|
157
|
+
if (!editor) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const result = await (0, _InsertTableModalDialog.openInsertTableDialog)(sdk.dialogs);
|
|
161
|
+
if (result) {
|
|
162
|
+
editor.actions.table(result);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
organizeLinks: ()=>{
|
|
166
|
+
if (!editor) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
let text = editor.getContent();
|
|
170
|
+
if (!text) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
text = _linkOrganizer.convertInlineToRef(text);
|
|
174
|
+
text = _linkOrganizer.rewriteRefs(text);
|
|
175
|
+
editor.setContent(text);
|
|
176
|
+
sdk.notifier.success('All your links are now references at the bottom of your document.');
|
|
177
|
+
},
|
|
178
|
+
embedExternalContent: async ()=>{
|
|
179
|
+
if (!editor) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const result = await (0, _EmdebExternalContentDialog.openEmbedExternalContentDialog)(sdk.dialogs);
|
|
183
|
+
if (result) {
|
|
184
|
+
editor.insert(result);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
addNewMedia: async ()=>{
|
|
188
|
+
if (!editor) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
try {
|
|
192
|
+
const { entity: asset } = await sdk.navigator.openNewAsset({
|
|
193
|
+
slideIn: {
|
|
194
|
+
waitForClose: true
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
const markdownLinks = await insertAssetsWithConfirmation([
|
|
198
|
+
asset
|
|
199
|
+
]);
|
|
200
|
+
editor.insert(markdownLinks);
|
|
201
|
+
} finally{
|
|
202
|
+
editor.focus();
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
linkExistingMedia: async ()=>{
|
|
206
|
+
if (!editor) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const assets = await sdk.dialogs.selectMultipleAssets({
|
|
211
|
+
locale: locale
|
|
212
|
+
});
|
|
213
|
+
const markdownLinks = await insertAssetsWithConfirmation(assets);
|
|
214
|
+
editor.insert(markdownLinks);
|
|
215
|
+
} finally{
|
|
216
|
+
editor.focus();
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
openZenMode: async ()=>{
|
|
220
|
+
if (!editor) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
const result = await (0, _ZenModeModalDialog.openZenMode)(sdk.dialogs, {
|
|
224
|
+
initialValue: editor.getContent(),
|
|
225
|
+
locale: props.locale
|
|
226
|
+
});
|
|
227
|
+
editor.setContent(result.value);
|
|
228
|
+
if (result.cursor) {
|
|
229
|
+
editor.setCursor(result.cursor);
|
|
230
|
+
}
|
|
231
|
+
editor.focus();
|
|
232
|
+
},
|
|
233
|
+
closeZenMode: ()=>{}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
MarkdownEditor: function() {
|
|
13
|
+
return MarkdownEditor;
|
|
14
|
+
},
|
|
15
|
+
MarkdownEditorConnected: function() {
|
|
16
|
+
return MarkdownEditorConnected;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _react = _interop_require_wildcard(require("react"));
|
|
20
|
+
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
21
|
+
const _fieldeditorshared = require("@contentful/field-editor-shared");
|
|
22
|
+
const _emotion = require("emotion");
|
|
23
|
+
const _MarkdownBottomBar = require("./components/MarkdownBottomBar");
|
|
24
|
+
const _MarkdownConstraints = require("./components/MarkdownConstraints");
|
|
25
|
+
const _MarkdownPreview = require("./components/MarkdownPreview");
|
|
26
|
+
const _MarkdownTabs = require("./components/MarkdownTabs");
|
|
27
|
+
const _MarkdownTextarea = require("./components/MarkdownTextarea/MarkdownTextarea");
|
|
28
|
+
const _MarkdownToolbar = require("./components/MarkdownToolbar");
|
|
29
|
+
const _CheatsheetModalDialog = require("./dialogs/CheatsheetModalDialog");
|
|
30
|
+
const _MarkdownActions = require("./MarkdownActions");
|
|
31
|
+
function _interop_require_default(obj) {
|
|
32
|
+
return obj && obj.__esModule ? obj : {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
37
|
+
if (typeof WeakMap !== "function") return null;
|
|
38
|
+
var cacheBabelInterop = new WeakMap();
|
|
39
|
+
var cacheNodeInterop = new WeakMap();
|
|
40
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
41
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
42
|
+
})(nodeInterop);
|
|
43
|
+
}
|
|
44
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
45
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
49
|
+
return {
|
|
50
|
+
default: obj
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
54
|
+
if (cache && cache.has(obj)) {
|
|
55
|
+
return cache.get(obj);
|
|
56
|
+
}
|
|
57
|
+
var newObj = {};
|
|
58
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
59
|
+
for(var key in obj){
|
|
60
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
61
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
62
|
+
if (desc && (desc.get || desc.set)) {
|
|
63
|
+
Object.defineProperty(newObj, key, desc);
|
|
64
|
+
} else {
|
|
65
|
+
newObj[key] = obj[key];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
newObj.default = obj;
|
|
70
|
+
if (cache) {
|
|
71
|
+
cache.set(obj, newObj);
|
|
72
|
+
}
|
|
73
|
+
return newObj;
|
|
74
|
+
}
|
|
75
|
+
const styles = {
|
|
76
|
+
container: (0, _emotion.css)({
|
|
77
|
+
display: 'flex',
|
|
78
|
+
flexDirection: 'column',
|
|
79
|
+
fontFamily: _f36tokens.default.fontStackPrimary
|
|
80
|
+
})
|
|
81
|
+
};
|
|
82
|
+
function MarkdownEditor(props) {
|
|
83
|
+
const [currentValue, setCurrentValue] = _react.useState(props.initialValue ?? '');
|
|
84
|
+
const [selectedTab, setSelectedTab] = _react.useState('editor');
|
|
85
|
+
const [editor, setEditor] = _react.useState(null);
|
|
86
|
+
const [canUploadAssets, setCanUploadAssets] = _react.useState(false);
|
|
87
|
+
_react.useEffect(()=>{
|
|
88
|
+
if (editor && props.onReady) {
|
|
89
|
+
props.onReady(editor);
|
|
90
|
+
setTimeout(()=>{
|
|
91
|
+
editor.refresh();
|
|
92
|
+
}, 1);
|
|
93
|
+
}
|
|
94
|
+
}, [
|
|
95
|
+
editor
|
|
96
|
+
]);
|
|
97
|
+
_react.useEffect(()=>{
|
|
98
|
+
props.sdk.access.can('create', 'Asset').then((value)=>{
|
|
99
|
+
setCanUploadAssets(value);
|
|
100
|
+
});
|
|
101
|
+
}, []);
|
|
102
|
+
_react.useEffect(()=>{
|
|
103
|
+
if (editor) {
|
|
104
|
+
editor.setReadOnly(props.disabled);
|
|
105
|
+
}
|
|
106
|
+
}, [
|
|
107
|
+
editor,
|
|
108
|
+
props.disabled
|
|
109
|
+
]);
|
|
110
|
+
const isActionDisabled = editor === null || props.disabled || selectedTab !== 'editor';
|
|
111
|
+
const direction = props.sdk.locales.direction[props.sdk.field.locale] ?? 'ltr';
|
|
112
|
+
const actions = _react.useMemo(()=>{
|
|
113
|
+
return (0, _MarkdownActions.createMarkdownActions)({
|
|
114
|
+
sdk: props.sdk,
|
|
115
|
+
editor,
|
|
116
|
+
locale: props.sdk.field.locale
|
|
117
|
+
});
|
|
118
|
+
}, [
|
|
119
|
+
editor
|
|
120
|
+
]);
|
|
121
|
+
const openMarkdownHelp = _react.useCallback(()=>{
|
|
122
|
+
(0, _CheatsheetModalDialog.openCheatsheetModal)(props.sdk.dialogs);
|
|
123
|
+
}, []);
|
|
124
|
+
return _react.createElement("div", {
|
|
125
|
+
className: styles.container,
|
|
126
|
+
"data-test-id": "markdown-editor"
|
|
127
|
+
}, _react.createElement(_MarkdownTabs.MarkdownTabs, {
|
|
128
|
+
active: selectedTab,
|
|
129
|
+
onSelect: (tab)=>{
|
|
130
|
+
setSelectedTab(tab);
|
|
131
|
+
}
|
|
132
|
+
}), _react.createElement(_MarkdownToolbar.MarkdownToolbar, {
|
|
133
|
+
mode: "default",
|
|
134
|
+
disabled: isActionDisabled,
|
|
135
|
+
canUploadAssets: canUploadAssets,
|
|
136
|
+
actions: actions
|
|
137
|
+
}), _react.createElement(_MarkdownTextarea.MarkdownTextarea, {
|
|
138
|
+
minHeight: props.minHeight,
|
|
139
|
+
mode: "default",
|
|
140
|
+
visible: selectedTab === 'editor',
|
|
141
|
+
disabled: isActionDisabled,
|
|
142
|
+
direction: direction,
|
|
143
|
+
onReady: (editor)=>{
|
|
144
|
+
editor.setContent(props.initialValue ?? '');
|
|
145
|
+
editor.setReadOnly(props.disabled);
|
|
146
|
+
setEditor(editor);
|
|
147
|
+
editor.events.onChange((value)=>{
|
|
148
|
+
const trimmedValue = value.replace(/^\s+$/gm, '');
|
|
149
|
+
props.saveValueToSDK(trimmedValue);
|
|
150
|
+
setCurrentValue(value);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}), selectedTab === 'preview' && _react.createElement(_MarkdownPreview.MarkdownPreview, {
|
|
154
|
+
direction: direction,
|
|
155
|
+
minHeight: props.minHeight,
|
|
156
|
+
mode: "default",
|
|
157
|
+
value: currentValue,
|
|
158
|
+
previewComponents: props.previewComponents
|
|
159
|
+
}), _react.createElement(_MarkdownBottomBar.MarkdownBottomBar, null, _react.createElement(_MarkdownBottomBar.MarkdownHelp, {
|
|
160
|
+
onClick: openMarkdownHelp
|
|
161
|
+
})), _react.createElement(_MarkdownConstraints.MarkdownConstraints, {
|
|
162
|
+
sdk: props.sdk,
|
|
163
|
+
value: currentValue
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
function MarkdownEditorConnected(props) {
|
|
167
|
+
return _react.createElement(_fieldeditorshared.FieldConnector, {
|
|
168
|
+
throttle: 300,
|
|
169
|
+
field: props.sdk.field,
|
|
170
|
+
isInitiallyDisabled: props.isInitiallyDisabled
|
|
171
|
+
}, ({ value , disabled , setValue , externalReset })=>{
|
|
172
|
+
return _react.createElement(MarkdownEditor, {
|
|
173
|
+
...props,
|
|
174
|
+
key: `markdown-editor-${externalReset}`,
|
|
175
|
+
initialValue: value,
|
|
176
|
+
disabled: disabled,
|
|
177
|
+
saveValueToSDK: setValue
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "newReferenceEditorFakeSdk", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return newReferenceEditorFakeSdk;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fieldeditortestutils = require("@contentful/field-editor-test-utils");
|
|
12
|
+
const _fixtures = require("./fixtures");
|
|
13
|
+
const newLink = (linkType, id)=>({
|
|
14
|
+
sys: {
|
|
15
|
+
id,
|
|
16
|
+
linkType,
|
|
17
|
+
type: 'Link'
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
function newReferenceEditorFakeSdk(props) {
|
|
21
|
+
const rawInitialValue = window.localStorage.getItem('initialValue');
|
|
22
|
+
const initialValue = rawInitialValue ? JSON.parse(rawInitialValue) : props?.initialValue;
|
|
23
|
+
const rawValidations = window.localStorage.getItem('fieldValidations');
|
|
24
|
+
const validations = rawValidations ? JSON.parse(rawValidations) : props?.validations;
|
|
25
|
+
const customizeMock = (field)=>{
|
|
26
|
+
return validations ? {
|
|
27
|
+
...field,
|
|
28
|
+
validations
|
|
29
|
+
} : field;
|
|
30
|
+
};
|
|
31
|
+
const [field, mitt] = (0, _fieldeditortestutils.createFakeFieldAPI)(customizeMock, initialValue);
|
|
32
|
+
const space = (0, _fieldeditortestutils.createFakeSpaceAPI)();
|
|
33
|
+
const locales = (0, _fieldeditortestutils.createFakeLocalesAPI)();
|
|
34
|
+
const entryLinks = [
|
|
35
|
+
newLink('Entry', _fixtures.entries.published.sys.id),
|
|
36
|
+
newLink('Entry', _fixtures.entries.changed.sys.id),
|
|
37
|
+
newLink('Entry', _fixtures.entries.empty.sys.id)
|
|
38
|
+
];
|
|
39
|
+
const assetLinks = [
|
|
40
|
+
newLink('Asset', _fixtures.assets.published.sys.id),
|
|
41
|
+
newLink('Asset', _fixtures.assets.changed.sys.id),
|
|
42
|
+
newLink('Asset', _fixtures.assets.empty.sys.id)
|
|
43
|
+
];
|
|
44
|
+
let selectorCounter = 0;
|
|
45
|
+
const delay = (ms)=>{
|
|
46
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
47
|
+
};
|
|
48
|
+
const localizeContentTypes = (contentTypes)=>{
|
|
49
|
+
return contentTypes.map((contentType)=>({
|
|
50
|
+
...contentType,
|
|
51
|
+
fields: contentType.fields.map((field)=>({
|
|
52
|
+
...field,
|
|
53
|
+
localized: true
|
|
54
|
+
}))
|
|
55
|
+
}));
|
|
56
|
+
};
|
|
57
|
+
const sdk = {
|
|
58
|
+
field,
|
|
59
|
+
locales,
|
|
60
|
+
cmaAdapter: (0, _fieldeditortestutils.createFakeCMAAdapter)({
|
|
61
|
+
Entry: {
|
|
62
|
+
get: async ({ entryId })=>{
|
|
63
|
+
if (props?.fetchDelay) {
|
|
64
|
+
await delay(props.fetchDelay);
|
|
65
|
+
}
|
|
66
|
+
if (entryId === _fixtures.entries.empty.sys.id) {
|
|
67
|
+
return _fixtures.entries.empty;
|
|
68
|
+
}
|
|
69
|
+
if (entryId === _fixtures.entries.published.sys.id) {
|
|
70
|
+
return _fixtures.entries.published;
|
|
71
|
+
}
|
|
72
|
+
if (entryId === _fixtures.entries.changed.sys.id) {
|
|
73
|
+
return _fixtures.entries.changed;
|
|
74
|
+
}
|
|
75
|
+
return Promise.reject({});
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
Asset: {
|
|
79
|
+
get: async ({ assetId })=>{
|
|
80
|
+
if (props?.fetchDelay) {
|
|
81
|
+
await delay(props.fetchDelay);
|
|
82
|
+
}
|
|
83
|
+
if (assetId === _fixtures.assets.empty.sys.id) {
|
|
84
|
+
return _fixtures.assets.empty;
|
|
85
|
+
}
|
|
86
|
+
if (assetId === _fixtures.assets.published.sys.id) {
|
|
87
|
+
return _fixtures.assets.published;
|
|
88
|
+
}
|
|
89
|
+
if (assetId === _fixtures.assets.changed.sys.id) {
|
|
90
|
+
return _fixtures.assets.changed;
|
|
91
|
+
}
|
|
92
|
+
return Promise.reject({});
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
Space: {
|
|
96
|
+
get: async (params)=>{
|
|
97
|
+
if (params.spaceId === _fixtures.spaces.indifferent.sys.id) {
|
|
98
|
+
return _fixtures.spaces.indifferent;
|
|
99
|
+
}
|
|
100
|
+
return Promise.reject({});
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
ContentType: {
|
|
104
|
+
get: async ({ contentTypeId })=>{
|
|
105
|
+
if (contentTypeId === _fixtures.contentTypes.published.sys.id) {
|
|
106
|
+
return _fixtures.contentTypes.published;
|
|
107
|
+
}
|
|
108
|
+
return Promise.reject({});
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
Locale: {
|
|
112
|
+
getMany: async ()=>_fixtures.locales.list
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
space: {
|
|
116
|
+
...space,
|
|
117
|
+
getCachedContentTypes () {
|
|
118
|
+
return localizeContentTypes(space.getCachedContentTypes());
|
|
119
|
+
},
|
|
120
|
+
getContentTypes () {
|
|
121
|
+
return Promise.resolve(space.getContentTypes().then((response)=>{
|
|
122
|
+
return {
|
|
123
|
+
...response,
|
|
124
|
+
items: localizeContentTypes(response.items)
|
|
125
|
+
};
|
|
126
|
+
}));
|
|
127
|
+
},
|
|
128
|
+
async getEntityScheduledActions () {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
dialogs: {
|
|
133
|
+
selectSingleAsset: async ()=>{
|
|
134
|
+
selectorCounter++;
|
|
135
|
+
return assetLinks[selectorCounter % assetLinks.length];
|
|
136
|
+
},
|
|
137
|
+
selectMultipleAssets: async ()=>{
|
|
138
|
+
selectorCounter++;
|
|
139
|
+
return selectorCounter % 2 ? assetLinks.slice(0, 2) : [
|
|
140
|
+
assetLinks[2]
|
|
141
|
+
];
|
|
142
|
+
},
|
|
143
|
+
selectSingleEntry: async ()=>{
|
|
144
|
+
selectorCounter++;
|
|
145
|
+
return entryLinks[selectorCounter % entryLinks.length];
|
|
146
|
+
},
|
|
147
|
+
selectMultipleEntries: async ()=>{
|
|
148
|
+
selectorCounter++;
|
|
149
|
+
return selectorCounter % 2 ? entryLinks.slice(0, 2) : [
|
|
150
|
+
entryLinks[2]
|
|
151
|
+
];
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
navigator: {
|
|
155
|
+
openNewAsset: async ()=>({
|
|
156
|
+
entity: newLink('Asset', _fixtures.assets.empty.sys.id)
|
|
157
|
+
}),
|
|
158
|
+
openAsset: async ()=>{
|
|
159
|
+
alert('open Asset in slide in');
|
|
160
|
+
return {};
|
|
161
|
+
},
|
|
162
|
+
openNewEntry: async ()=>({
|
|
163
|
+
entity: newLink('Entry', _fixtures.entries.empty.sys.id)
|
|
164
|
+
}),
|
|
165
|
+
openEntry: async ()=>{
|
|
166
|
+
alert('open entry in slide in');
|
|
167
|
+
return {};
|
|
168
|
+
},
|
|
169
|
+
onSlideInNavigation: ()=>()=>({})
|
|
170
|
+
},
|
|
171
|
+
access: {
|
|
172
|
+
can: async ()=>true
|
|
173
|
+
},
|
|
174
|
+
ids: {
|
|
175
|
+
space: 'space-id',
|
|
176
|
+
environment: 'environment-id'
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
return [
|
|
180
|
+
sdk,
|
|
181
|
+
mitt
|
|
182
|
+
];
|
|
183
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
changed: function() {
|
|
13
|
+
return _changed_assetjson.default;
|
|
14
|
+
},
|
|
15
|
+
empty: function() {
|
|
16
|
+
return _empty_assetjson.default;
|
|
17
|
+
},
|
|
18
|
+
published: function() {
|
|
19
|
+
return _published_assetjson.default;
|
|
20
|
+
},
|
|
21
|
+
invalid: function() {
|
|
22
|
+
return _invalid_assetjson.default;
|
|
23
|
+
},
|
|
24
|
+
created: function() {
|
|
25
|
+
return _created_assetjson.default;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const _changed_assetjson = _interop_require_default(require("./changed_asset.json"));
|
|
29
|
+
const _created_assetjson = _interop_require_default(require("./created_asset.json"));
|
|
30
|
+
const _empty_assetjson = _interop_require_default(require("./empty_asset.json"));
|
|
31
|
+
const _invalid_assetjson = _interop_require_default(require("./invalid_asset.json"));
|
|
32
|
+
const _published_assetjson = _interop_require_default(require("./published_asset.json"));
|
|
33
|
+
function _interop_require_default(obj) {
|
|
34
|
+
return obj && obj.__esModule ? obj : {
|
|
35
|
+
default: obj
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "published", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _published_content_typejson.default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _published_content_typejson = _interop_require_default(require("./published_content_type.json"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
changed: function() {
|
|
13
|
+
return _changed_entryjson.default;
|
|
14
|
+
},
|
|
15
|
+
empty: function() {
|
|
16
|
+
return _empty_entryjson.default;
|
|
17
|
+
},
|
|
18
|
+
published: function() {
|
|
19
|
+
return _published_entryjson.default;
|
|
20
|
+
},
|
|
21
|
+
invalid: function() {
|
|
22
|
+
return _invalid_entryjson.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _changed_entryjson = _interop_require_default(require("./changed_entry.json"));
|
|
26
|
+
const _empty_entryjson = _interop_require_default(require("./empty_entry.json"));
|
|
27
|
+
const _invalid_entryjson = _interop_require_default(require("./invalid_entry.json"));
|
|
28
|
+
const _published_entryjson = _interop_require_default(require("./published_entry.json"));
|
|
29
|
+
function _interop_require_default(obj) {
|
|
30
|
+
return obj && obj.__esModule ? obj : {
|
|
31
|
+
default: obj
|
|
32
|
+
};
|
|
33
|
+
}
|